package cit.project.capeclear;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

public class Item implements Parcelable{
	
	int code;
	String title;
	String description;
	String category;
	Float price;
	int shipment;
	String shopName;
	boolean checked;
	int quantity;
	
	//Parcelable.Creator<Item> CREATOR;
	
	public Item(int c, String t, String d, String cat, float p, int s, String sn){
		code = c;
		title = t;
		description = d;
		category = cat;
		price = p;
		shipment = s;
		shopName = sn;
		checked=false;
		quantity=1;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		Log.v("ITEM", "writeToParcel..."+ flags);
	      dest.writeInt(code);
	      dest.writeString(title);
	      dest.writeString(description);
	      dest.writeString(category);
	      dest.writeFloat(price);
	      dest.writeInt(shipment);
	      dest.writeString(shopName);
	      dest.writeByte((byte) (checked ? 1 : 0));     //if myBoolean == true, byte == 1
	      dest.writeInt(quantity);
	}
	


	public static final Parcelable.Creator<Item> CREATOR = new Parcelable.Creator<Item>() {
	    public Item createFromParcel(Parcel in) {
	        return new Item(in);
	    }

	    public Item[] newArray(int size) {
	        return new Item[size];
	    }
	};
	  /**
	   * This will be used only by the MyCreator
	   * @param source
	   */
	  public Item(Parcel source){
	        /*
	         * Reconstruct from the Parcel
	         */
	      
	        code = source.readInt();
	        title = source.readString();
	        description = source.readString();
	        category = source.readString();
	        price = source.readFloat();
	        shipment = source.readInt();
	        shopName = source.readString();
	        checked = source.readByte() == 1;     //myBoolean == true if byte == 1
	        quantity = source.readInt();
	  }

}
